// 可迭代对象
const iterable = {
    names: [111, 222, 333],
    [Symbol.iterator]: function () {
        let index = 0
        return {
            next: () => {
                if (index < this.names.length) {
                    return { done: false, value: this.names[index++] }
                } else {
                    return { done: true, value: undefined }
                }
            }
        }
    }
}
// 生成迭代器
const iteraotr = iterable[Symbol.iterator]()
console.log(iteraotr.next());

const iteraotr1 = iterable[Symbol.iterator]()
console.log(iteraotr1.next());

// for ... of 遍历可迭代对象
// {} is not iterable
for (const item of iterable) {
    console.log(item);
}